/*
 * SignatureAlgorithm.java
 *
 * Created on 21 March 2006, 11:28
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.tastefuljava.minica;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author PERRYM
 */

public class SignatureAlgorithm {
    private static final SignatureAlgorithm ALGORITHMS[];

    private String digest;
    private String crypto;
    private String name;

    private SignatureAlgorithm(String digest, String crypto, String name) {
        this.digest = digest;
        this.crypto = crypto;
        this.name = name;
    }

    public static SignatureAlgorithm[] getAll() {
        return (SignatureAlgorithm[])ALGORITHMS.clone();
    }

    public static SignatureAlgorithm[] getForCrypto(String crypto) {
        List<SignatureAlgorithm> list = new ArrayList<SignatureAlgorithm>();
        for (int i = 0; i < ALGORITHMS.length; ++i) {
            SignatureAlgorithm alg = ALGORITHMS[i];
            if (crypto.equalsIgnoreCase(alg.crypto)) {
                list.add(alg);
            }
        }
        return list.toArray(
                new SignatureAlgorithm[list.size()]);
    }

    @Override
    public String toString() {
        return digest + "/" + crypto;
    }

    public String getDigest() {
        return digest;
    }

    public String getCrypto() {
        return crypto;
    }

    public String getName() {
        return name;
    }

    static {
        ALGORITHMS = new SignatureAlgorithm[] {
            new SignatureAlgorithm("SHA1", "RSA", "SHA1withRSA"),
            new SignatureAlgorithm("MD2", "RSA", "MD2withRSA"),
            new SignatureAlgorithm("MD5", "RSA", "MD5withRSA"),
            new SignatureAlgorithm("SHA1", "DSA", "SHA1withDSA")
        };
    }
}
